package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.pojo.Job;
import com.example.pojo.JobInfo;
import com.example.service.JobInfoService;
import com.example.mapper.JobInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author Ansenown
* @description 针对表【job_info】的数据库操作Service实现
* @createDate 2025-03-29 14:45:20
*/
@Service
public class JobInfoServiceImpl extends ServiceImpl<JobInfoMapper, JobInfo>
    implements JobInfoService{

    @Autowired
    private JobInfoMapper jobInfoMapper;


    @Override
    public void insertRejectListReason(List<String> idlist, Integer useridentityfer, String msg) {

        List<Integer> intIdList = idlist.stream()
                .map(Integer::parseInt)
                .collect(Collectors.toList());

        List<JobInfo> jobInfoList = new ArrayList<>();
        for (Integer id : intIdList){
            JobInfo jobInfo = new JobInfo();
            jobInfo.setJobId(id);
            jobInfo.setExamineUser(useridentityfer);
            jobInfo.setExamineOption("批量驳回");
            jobInfo.setExamineInfo(msg);
            jobInfo.setCreateTime(LocalDateTime.now());
            jobInfoList.add(jobInfo);
        }
        saveBatch(jobInfoList);
    }

    @Override
    public void insertAccessListReason(List<String> idList, Integer useridentityfer) {
        List<Integer> intIdList = idList.stream()
                .map(Integer::parseInt)
                .collect(Collectors.toList());

        List<JobInfo> jobInfoList = new ArrayList<>();
        for (Integer id : intIdList){
            JobInfo jobInfo = new JobInfo();
            jobInfo.setJobId(id);
            jobInfo.setExamineUser(useridentityfer);
            jobInfo.setExamineOption("批量同意");
            jobInfo.setExamineInfo("批量处理");
            jobInfo.setCreateTime(LocalDateTime.now());
            jobInfoList.add(jobInfo);
        }
        saveBatch(jobInfoList);
    }

    @Override
    public List<JobInfo> getJobInfos(Integer useridentityfer) {
        List<JobInfo> jobList = jobInfoMapper.selectList(new LambdaQueryWrapper<JobInfo>().eq(JobInfo::getExamineUser,useridentityfer));
        return jobList;
    }

    @Override
    public List<Integer> getCompleteJobInfos(int useridentityfer) {
        List<JobInfo> jobList = jobInfoMapper.selectList(new LambdaQueryWrapper<JobInfo>().eq(JobInfo::getExamineUser,useridentityfer));
        List<Integer> idList = new ArrayList<>();
        for (JobInfo jobInfo : jobList){
            idList.add(jobInfo.getJobId());
        }
        return idList;
    }
}




